<!--
tabs-item: lab: tab显示字段; badge: 标记
-->
<template>
  <ul class="custom-tabs-box">
    <el-badge v-for="(item, index) in tabsArr" :key="index" v-bind="item.badge">
      <li
        :class="{active: index === tabsActiveIndex}"
        class="tabs-item"
        @click.stop="tabsHandle(index)"
      >
        <span class="item-font">{{ item.lab }}</span>
        <span class="item-border" />
      </li>
    </el-badge>
  </ul>
</template>
<script>
export default {
  name: 'CustomTabs',
  props: {
    activeIndex: {
      type: Number,
      default: 0
    },
    tabsArr: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      tabsActiveIndex: null
    }
  },
  watch: {
    activeIndex: {
      immediate: true,
      handler(val) {
        this.tabsActiveIndex = val
      }
    }
  },
  methods: {
    tabsHandle(index) {
      this.tabsActiveIndex = index
      this.$emit('returnIndex', index)
    }
  }
}
</script>
<style lang="less">
@import '../../../assets/var.less';

.custom-tabs-box {
  padding-left: 0;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 10px;

  .tabs-item {
    list-style: none;
    padding: 0 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;

    .item-font {
      display: flex;
      align-items: center;
      height: 100%;
      font-size: 14px;
      font-weight: bold;
      color: @weakFontColor;
    }

    .item-border {
      display: inline-block;
      height: 2px;
      width: 20px;
      border-radius: 2px;
      background-color: transparent;
    }

    &.active {
      font-size: 20px;
      font-weight: bold;
      line-height: 28px;

      .item-font {
        font-size: 20px;
        color: @themeBlue;
      }

      .item-border {
        background-color: @themeBlue;
      }
    }
  }

  .el-badge__content.is-fixed {
    right: 25px;
  }
}
</style>
